﻿using Newtonsoft.Json;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Net.Cache;
using System.Net.Security;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using System.Text;

namespace McsWeb.Common
{
    public class WebApiHelper
    {
        /// <summary>
        /// Get请求
        /// </summary>
        public static T Get<T>(string webApi, string queryStr)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webApi + "?" + queryStr);

            //加入头信息
            //request.Headers.Add("Token", Token.ToString()); 

            request.Method = "GET";
            request.ContentType = "application/json";
            //request.Timeout = 500;// 90000;
            request.Headers.Set("Pragma", "no-cache");
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream streamReceive = response.GetResponseStream();
            StreamReader streamReader = new StreamReader(streamReceive, Encoding.UTF8);
            string strResult = streamReader.ReadToEnd();

            streamReader.Close();
            streamReceive.Close();
            request.Abort();
            response.Close();

            return JsonConvert.DeserializeObject<T>(strResult);
        }
    }
}